楠渡余生楠渡余生
首页
笔记
作品集
留言板
关于
GitHub
CSDN
首页
笔记
作品集
留言板
关于
GitHub
CSDN
  • 前端开发

    • React Server Components(RSC)学习笔记

      • React Server Components(RSC)学习笔记
    • 全栈框架学习笔记

      • 全栈框架学习笔记
    • jQuery 学习笔记

      • jQuery 学习笔记
    • React 学习笔记

      • React 学习笔记
    • AJAX 学习笔记

      • AJAX 学习笔记
    • Axios 完整学习笔记

      • Axios 完整学习笔记
    • CSS 属性速查手册

      • CSS 属性速查手册
    • HTML5 与 CSS 综合学习笔记

      • HTML5 与 CSS 综合学习笔记
    • JavaScript 学习笔记

      • JavaScript 学习笔记
    • Promise 学习笔记

      • Promise 学习笔记
    • Tailwind CSS 完整笔记

      • Tailwind CSS 完整笔记
    • TypeScript 快速上手

      • TypeScript 快速上手
    • Vue3 学习笔记

      • Vue3 学习笔记
  • 元框架与全栈路由

    • Next.js App Router 最佳实践

      • Next.js App Router 最佳实践
    • 跨域与服务端组件数据预取

      • 跨域与服务端组件数据预取
  • 现代数据流与安全

    • Prisma Schema 全栈类型生成

      • Prisma Schema 全栈类型生成
    • Supabase RLS 行级安全策略

      • Supabase RLS 行级安全策略
  • 商业化与支付闭环

    • SaaS 订阅制用户表结构设计

      • SaaS 订阅制用户表结构设计
    • Stripe Webhook 接入避坑指南

      • Stripe Webhook 接入避坑指南
  • 零运维与边缘计算

    • Cloudflare 基础防护与 CDN

      • Cloudflare 基础防护与 CDN
    • Vercel 自动化部署与环境变量

      • Vercel 自动化部署与环境变量
  • AI 赋能与集成

    • Vercel AI SDK 流式输出实战

      • Vercel AI SDK 流式输出实战
  • 增长、监控与运营

    • Resend 事务性邮件模板

      • Resend 事务性邮件模板
    • Sentry 前端异常捕获与报警

      • Sentry 前端异常捕获与报警
  • Node.js 深入学习

    • MongoDB 常用命令速查表

      • MongoDB 常用命令速查表
    • Node.js + MongoDB 生产级最佳实践指南

      • Node.js + MongoDB 生产级最佳实践指南
    • Node.js Express 框架

      • Node.js Express 框架
    • Node.js HTTP 模块

      • Node.js HTTP 模块
    • Node.js NPM 包管理

      • Node.js NPM 包管理
    • Node.js 文件系统模块

      • Node.js 文件系统模块
    • Node.js 模块化设计

      • Node.js 模块化设计
  • 后端开发

    • Express 基本使用

      • Express 基本使用
    • Node.js 学习笔记

      • Node.js 学习笔记
    • SpringBoot 完整学习笔记

      • SpringBoot 完整学习笔记
  • 开发工具

    • Windows + WSL + Docker 踩坑与通关指南

      • Windows + WSL + Docker 踩坑与通关指南
    • GitHub 新手完全指南

      • GitHub 新手完全指南
    • 个人博客搭建指南

      • 个人博客搭建指南

CSS 属性速查手册

本手册按功能分类,列出所有常用的 CSS 属性及其用处,方便快速查找。


一、文本样式属性

1. 颜色相关

属性名用处示例值
color设置文字颜色red, #ff0000, rgb(255,0,0)
opacity设置元素透明度(0-1)0.5, 1

2. 字体相关

属性名用处示例值
font-family设置字体系列Arial, "Microsoft YaHei", sans-serif
font-size设置字体大小16px, 1.5em, 2rem, 100%
font-weight设置字体粗细normal, bold, 100-900
font-style设置字体样式(斜体等)normal, italic, oblique
font-variant设置字体变体normal, small-caps
font字体复合属性(简写)italic bold 16px/1.5 Arial
line-height设置行高1.5, 24px, 150%

3. 文本格式化

属性名用处示例值
text-align设置文本水平对齐left, right, center, justify
text-align-last设置最后一行对齐方式left, right, center, justify
vertical-align设置垂直对齐(行内/表格元素)baseline, top, middle, bottom
text-decoration设置文本装饰线none, underline, overline, line-through
text-decoration-line装饰线位置underline, overline, line-through
text-decoration-color装饰线颜色red, #ff0000
text-decoration-style装饰线样式solid, dashed, dotted, wavy
text-decoration-thickness装饰线粗细2px, auto
text-transform设置文本大小写转换none, capitalize, uppercase, lowercase
text-indent设置首行缩进2em, 32px
text-shadow设置文字阴影2px 2px 4px rgba(0,0,0,0.5)
text-overflow设置文本溢出处理clip, ellipsis
text-wrap设置文本换行方式wrap, nowrap, balance

4. 字符和单词

属性名用处示例值
letter-spacing设置字符间距2px, 0.1em, normal
word-spacing设置单词间距5px, normal
word-break设置单词换行规则normal, break-all, keep-all
word-wrap设置长单词换行(同 overflow-wrap)normal, break-word
overflow-wrap设置长单词换行normal, break-word, anywhere
white-space设置空白符处理方式normal, nowrap, pre, pre-wrap, pre-line
tab-size设置制表符宽度4, 8
hyphens设置连字符none, manual, auto

5. 书写模式

属性名用处示例值
writing-mode设置书写方向horizontal-tb, vertical-rl, vertical-lr
direction设置文本方向ltr, rtl
unicode-bidi设置 Unicode 双向算法normal, embed, bidi-override

二、盒模型属性

1. 尺寸

属性名用处示例值
width设置元素宽度300px, 50%, auto
height设置元素高度200px, 50vh, auto
min-width设置最小宽度200px, 50%
max-width设置最大宽度1200px, 100%
min-height设置最小高度100px, 50vh
max-height设置最大高度500px, 80vh
box-sizing设置盒模型计算方式content-box, border-box

💡 box-sizing 详解:

/* content-box(默认值)*/
.box1 {
  box-sizing: content-box;
  width: 300px;           /* 仅内容宽度 */
  padding: 20px;
  border: 1px solid #000;
  /* 实际总宽度 = 300 + 20*2 + 1*2 = 342px */
}

/* border-box(推荐)*/
.box2 {
  box-sizing: border-box;
  width: 300px;           /* 包含padding和border的总宽度 */
  padding: 20px;
  border: 1px solid #000;
  /* 实际总宽度 = 300px */
  /* 内容宽度 = 300 - 20*2 - 1*2 = 258px */
}

⚠️ 注意事项:

  • 默认值问题: 浏览器默认使用content-box,布局计算复杂
  • 全局设置: 推荐在项目开始时全局设置为border-box
  • 继承性: box-sizing不继承,需要显式设置
  • 兼容性: 所有现代浏览器(含IE8+)均原生支持,无需加任何前缀
  • 百分比宽度: border-box配合百分比宽度更容易控制布局
/* 常见错误示例 */
.wrong {
  width: 100%;        /* ❌ 会超出父容器 */
  padding: 20px;
  border: 1px solid #000;
}

/* 正确做法 */
.correct {
  box-sizing: border-box;
  width: 100%;        /* ✅ 正好填满父容器 */
  padding: 20px;
  border: 1px solid #000;
}

/* 全局推荐设置 */
*, *::before, *::after {
  box-sizing: border-box;
}

🎯 实际应用场景:

/* 场景1:响应式网格布局 */
.grid-item {
  box-sizing: border-box;
  width: 33.333%;  /* 三列布局 */
  padding: 15px;   /* 不影响宽度 */
  border: 1px solid #ddd;
  float: left;
}

/* 场景2:表单元素统一大小 */
input, textarea, button {
  box-sizing: border-box;
  width: 100%;
  padding: 10px;
  border: 2px solid #ccc;
  /* 所有元素宽度一致 */
}

/* 场景3:卡片组件 */
.card {
  box-sizing: border-box;
  width: 300px;
  padding: 20px;
  border: 1px solid #e0e0e0;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  /* 固定宽度,内边距和边框不影响布局 */
}

/* 场景4:Flexbox容器 */
.flex-container {
  display: flex;
  gap: 20px;
}

.flex-item {
  box-sizing: border-box;
  flex: 1;         /* 平分空间 */
  padding: 15px;   /* padding不破坏等分 */
  border: 2px solid #333;
}

2. 内边距(Padding)

属性名用处示例值
padding设置内边距(四边简写)20px, 10px 20px, 10px 20px 30px 40px
padding-top设置上内边距10px, 1em
padding-right设置右内边距10px, 1em
padding-bottom设置下内边距10px, 1em
padding-left设置左内边距10px, 1em

3. 外边距(Margin)

属性名用处示例值
margin设置外边距(四边简写)20px, 10px 20px, 0 auto
margin-top设置上外边距10px, 1em
margin-right设置右外边距10px, auto
margin-bottom设置下外边距10px, 1em
margin-left设置左外边距10px, auto

4. 边框(Border)

属性名用处示例值
border设置边框(简写)1px solid #000
border-width设置边框宽度1px, thin, medium, thick
border-style设置边框样式solid, dashed, dotted, double, none
border-color设置边框颜色red, #ff0000
border-top设置上边框1px solid #000
border-right设置右边框1px solid #000
border-bottom设置下边框1px solid #000
border-left设置左边框1px solid #000
border-top-width设置上边框宽度2px
border-top-style设置上边框样式solid
border-top-color设置上边框颜色red
border-radius设置圆角10px, 50%, 10px 20px
border-top-left-radius设置左上圆角10px
border-top-right-radius设置右上圆角10px
border-bottom-left-radius设置左下圆角10px
border-bottom-right-radius设置右下圆角10px
border-image设置边框图片url(border.png) 30 round
border-image-source边框图片源url(border.png)
border-image-slice边框图片切片30
border-image-width边框图片宽度10px
border-image-repeat边框图片重复方式stretch, repeat, round

5. 轮廓(Outline)

属性名用处示例值
outline设置轮廓(不占空间)2px solid red
outline-width设置轮廓宽度2px, thin, medium, thick
outline-style设置轮廓样式solid, dashed, dotted, none
outline-color设置轮廓颜色red, invert
outline-offset设置轮廓偏移5px, -5px

三、背景属性

属性名用处示例值
background背景复合属性(简写)red url(bg.jpg) no-repeat center/cover
background-color设置背景颜色red, #ff0000, transparent
background-image设置背景图片url(image.jpg), linear-gradient(red, blue)
background-repeat设置背景重复方式repeat, no-repeat, repeat-x, repeat-y
background-position设置背景位置center, top left, 50% 50%, 10px 20px
background-size设置背景大小auto, cover, contain, 100px 200px, 50%
background-attachment设置背景固定方式scroll, fixed, local
background-origin设置背景定位区域padding-box, border-box, content-box
background-clip设置背景裁剪区域border-box, padding-box, content-box, text
background-blend-mode设置背景混合模式normal, multiply, screen, overlay

四、显示与可见性

属性名用处示例值
display设置元素显示类型block, inline, inline-block, flex, grid, none
visibility设置元素可见性(占空间)visible, hidden, collapse
opacity设置元素透明度0 到 1
overflow设置溢出处理方式visible, hidden, scroll, auto
overflow-x设置水平溢出处理visible, hidden, scroll, auto
overflow-y设置垂直溢出处理visible, hidden, scroll, auto
overflow-wrap设置长单词换行normal, break-word
clip裁剪绝对定位元素(已废弃,请用 clip-path)rect(0, 100px, 100px, 0)
clip-path设置裁剪路径circle(50%), polygon(...)

五、定位属性

属性名用处示例值
position设置定位方式static, relative, absolute, fixed, sticky
top设置距顶部距离(已定位元素)10px, 50%, auto
right设置距右边距离10px, 50%, auto
bottom设置距底部距离10px, 50%, auto
left设置距左边距离10px, 50%, auto
inset设置四边距离(简写)10px, 0 10px, 10px 20px 30px 40px
z-index设置层叠顺序1, 100, -1, auto
float设置浮动left, right, none
clear清除浮动left, right, both, none

💡 position 定位详解:

/* static - 静态定位(默认) */
.static {
  position: static;
  /* top/right/bottom/left无效 */
  /* 按照正常文档流排列 */
}

/* relative - 相对定位 */
.relative {
  position: relative;
  top: 20px;     /* 相对原位置向下偏移20px */
  left: 30px;    /* 相对原位置向右偏移30px */
  /* 元素仍占据原来的空间 */
  /* 常用作absolute的定位参照 */
}

/* absolute - 绝对定位 */
.absolute {
  position: absolute;
  top: 0;        /* 相对最近的已定位祖先元素 */
  right: 0;
  /* 脱离文档流,不占空间 */
  /* 如果没有已定位祖先,相对body定位 */
}

/* fixed - 固定定位 */
.fixed {
  position: fixed;
  bottom: 20px;  /* 相对浏览器视口 */
  right: 20px;
  /* 脱离文档流 */
  /* 滚动页面时保持固定位置 */
}

/* sticky - 粘性定位 */
.sticky {
  position: sticky;
  top: 0;        /* 滚动到阈值时固定 */
  /* 平时是relative,滚动到阈值后变fixed */
  /* 不脱离文档流 */
}

⚠️ 注意事项:

  • 定位参照: absolute相对最近的已定位(非static)祖先元素
  • z-index: 只对已定位元素(非static)有效
  • 性能影响: fixed和absolute会触发重绘,慎用大量定位元素
  • sticky兼容性: IE不支持sticky,需要fallback方案
  • 脱离文档流: absolute和fixed会导致父元素高度塌陷
  • 百分比定位: 百分比值相对于包含块的尺寸
/* 常见错误:父元素没有定位 */
.parent {
  /* ❌ 没有设置position */
}
.child {
  position: absolute;
  top: 0;
  /* 会相对body定位,而不是.parent */
}

/* 正确做法 */
.parent {
  position: relative;  /* ✅ 设置为定位参照 */
}
.child {
  position: absolute;
  top: 0;              /* 现在相对.parent定位 */
}

/* sticky需要指定阈值 */
.sticky-wrong {
  position: sticky;  /* ❌ 没有top/bottom值 */
}
.sticky-correct {
  position: sticky;
  top: 0;            /* ✅ 指定粘性阈值 */
}

🎯 实际应用场景:

/* 场景1:固定导航栏 */
.navbar {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  background: #333;
  z-index: 1000;
  /* 页面滚动时始终显示 */
}
body {
  padding-top: 60px;  /* 避免内容被导航栏遮挡 */
}

/* 场景2:模态框/弹窗居中 */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}
.modal-content {
  position: relative;
  background: white;
  padding: 20px;
  border-radius: 8px;
}

/* 场景3:角标/徽章 */
.icon-container {
  position: relative;
  display: inline-block;
}
.badge {
  position: absolute;
  top: -5px;
  right: -5px;
  background: red;
  color: white;
  border-radius: 50%;
  padding: 2px 6px;
  font-size: 12px;
}

/* 场景4:粘性表头 */
.table-header {
  position: sticky;
  top: 0;
  background: white;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  z-index: 10;
  /* 滚动表格时表头保持可见 */
}

/* 场景5:回到顶部按钮 */
.back-to-top {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 50px;
  height: 50px;
  background: #007bff;
  color: white;
  border-radius: 50%;
  cursor: pointer;
  z-index: 999;
}

六、Flexbox 布局属性

1. 容器属性

属性名用处示例值
display: flex启用 Flex 布局flex, inline-flex
flex-direction设置主轴方向row, row-reverse, column, column-reverse
flex-wrap设置换行方式nowrap, wrap, wrap-reverse
flex-flowflex-direction 和 flex-wrap 简写row wrap
justify-content设置主轴对齐方式flex-start, flex-end, center, space-between, space-around, space-evenly
align-items设置交叉轴对齐方式flex-start, flex-end, center, baseline, stretch
align-content设置多行对齐方式flex-start, flex-end, center, space-between, space-around, stretch
gap设置项目间距20px, 1rem
row-gap设置行间距10px
column-gap设置列间距20px

2. 项目属性

属性名用处示例值
order设置项目排序0, 1, -1
flex-grow设置放大比例0, 1, 2
flex-shrink设置缩小比例1, 0
flex-basis设置基础大小auto, 200px, 50%
flexflex-grow、flex-shrink、flex-basis 简写1, 0 1 auto, 1 1 200px
align-self设置单个项目对齐方式auto, flex-start, flex-end, center, baseline, stretch

七、Grid 布局属性

1. 容器属性

属性名用处示例值
display: grid启用 Grid 布局grid, inline-grid
grid-template-columns定义列100px 200px, 1fr 2fr, repeat(3, 1fr)
grid-template-rows定义行100px 200px, auto 1fr auto
grid-template-areas定义网格区域"header header" "nav main"
grid-templategrid-template-rows、columns、areas 简写复杂值
grid-column-gap设置列间距(旧语法)20px
grid-row-gap设置行间距(旧语法)10px
grid-gap设置行列间距(旧语法)10px 20px
gap设置行列间距(新语法)20px, 10px 20px
row-gap设置行间距10px
column-gap设置列间距20px
justify-items设置项目水平对齐start, end, center, stretch
align-items设置项目垂直对齐start, end, center, stretch
place-itemsjustify-items 和 align-items 简写center, start end
justify-content设置网格水平对齐start, end, center, space-between, space-around, space-evenly
align-content设置网格垂直对齐start, end, center, space-between, space-around, space-evenly
place-contentjustify-content 和 align-content 简写center, start end
grid-auto-columns设置自动列宽100px, 1fr
grid-auto-rows设置自动行高100px, minmax(100px, auto)
grid-auto-flow设置自动放置方向row, column, dense
gridGrid 所有属性简写复杂值

2. 项目属性

属性名用处示例值
grid-column-start设置列起始线1, 2, span 2
grid-column-end设置列结束线3, span 2
grid-columngrid-column-start 和 end 简写1 / 3, span 2
grid-row-start设置行起始线1, 2, span 2
grid-row-end设置行结束线3, span 2
grid-rowgrid-row-start 和 end 简写1 / 3, span 2
grid-area设置网格区域或位置header, 1 / 1 / 2 / 3
justify-self设置单个项目水平对齐start, end, center, stretch
align-self设置单个项目垂直对齐start, end, center, stretch
place-selfjustify-self 和 align-self 简写center, start end

八、变换属性(Transform)

属性名用处示例值
transform设置 2D/3D 变换rotate(45deg), scale(1.5), translate(10px, 20px)
transform-origin设置变换原点center, top left, 50% 50%
transform-style设置 3D 变换样式flat, preserve-3d
perspective设置透视距离1000px
perspective-origin设置透视原点50% 50%, center
backface-visibility设置背面可见性visible, hidden

transform 函数值

函数用处示例
translate(x, y)2D 平移translate(50px, 100px)
translateX(x)X 轴平移translateX(50px)
translateY(y)Y 轴平移translateY(50px)
translateZ(z)Z 轴平移translateZ(50px)
translate3d(x,y,z)3D 平移translate3d(50px, 100px, 50px)
scale(x, y)2D 缩放scale(1.5), scale(1.5, 2)
scaleX(x)X 轴缩放scaleX(1.5)
scaleY(y)Y 轴缩放scaleY(1.5)
scaleZ(z)Z 轴缩放scaleZ(2)
scale3d(x,y,z)3D 缩放scale3d(1.5, 1.5, 2)
rotate(angle)2D 旋转rotate(45deg)
rotateX(angle)绕 X 轴旋转rotateX(45deg)
rotateY(angle)绕 Y 轴旋转rotateY(45deg)
rotateZ(angle)绕 Z 轴旋转rotateZ(45deg)
rotate3d(x,y,z,a)3D 旋转rotate3d(1, 1, 1, 45deg)
skew(x, y)2D 倾斜skew(20deg, 10deg)
skewX(angle)X 轴倾斜skewX(20deg)
skewY(angle)Y 轴倾斜skewY(20deg)
matrix(...)2D 矩阵变换matrix(1, 0, 0, 1, 0, 0)
matrix3d(...)3D 矩阵变换16个参数

九、过渡属性(Transition)

属性名用处示例值
transition过渡复合属性(简写)all 0.3s ease
transition-property设置过渡属性all, width, opacity
transition-duration设置过渡时长0.3s, 300ms
transition-timing-function设置过渡时间函数ease, linear, ease-in, ease-out, ease-in-out, cubic-bezier(...)
transition-delay设置过渡延迟0.1s, 100ms

十、动画属性(Animation)

属性名用处示例值
animation动画复合属性(简写)slide 1s ease infinite
animation-name设置动画名称slide, fade
animation-duration设置动画时长1s, 1000ms
animation-timing-function设置动画时间函数ease, linear, ease-in, ease-out, steps(4)
animation-delay设置动画延迟0.5s, 500ms
animation-iteration-count设置动画重复次数1, 3, infinite
animation-direction设置动画方向normal, reverse, alternate, alternate-reverse
animation-fill-mode设置动画填充模式none, forwards, backwards, both
animation-play-state设置动画播放状态running, paused

十一、滤镜与特效

属性名用处示例值
filter设置图形滤镜效果blur(5px), brightness(1.5), grayscale(100%)
backdrop-filter设置背景滤镜效果blur(10px)
mix-blend-mode设置元素混合模式normal, multiply, screen, overlay
background-blend-mode设置背景混合模式normal, multiply, screen, overlay
isolation设置混合隔离auto, isolate

filter 函数值

函数用处示例
blur(px)模糊blur(5px)
brightness(%)亮度brightness(150%)
contrast(%)对比度contrast(200%)
grayscale(%)灰度grayscale(100%)
hue-rotate(deg)色相旋转hue-rotate(90deg)
invert(%)反转invert(100%)
opacity(%)不透明度opacity(50%)
saturate(%)饱和度saturate(200%)
sepia(%)褐色sepia(100%)
drop-shadow(...)阴影drop-shadow(2px 2px 5px rgba(0,0,0,0.5))

十二、阴影效果

属性名用处示例值
box-shadow设置盒子阴影2px 2px 5px rgba(0,0,0,0.3)
text-shadow设置文字阴影2px 2px 4px rgba(0,0,0,0.5)

十三、列表属性

属性名用处示例值
list-style列表样式(简写)circle inside
list-style-type设置列表标记类型none, disc, circle, square, decimal, upper-alpha
list-style-position设置列表标记位置inside, outside
list-style-image设置列表标记图片url(marker.png), none

十四、表格属性

属性名用处示例值
border-collapse设置表格边框合并separate, collapse
border-spacing设置单元格间距10px, 5px 10px
caption-side设置表格标题位置top, bottom
empty-cells设置空单元格显示show, hide
table-layout设置表格布局算法auto, fixed

十五、多列布局

属性名用处示例值
columns多列布局(简写)3, 200px 3
column-count设置列数3, auto
column-width设置列宽200px, auto
column-gap设置列间距20px, normal
column-rule设置列边框(简写)1px solid #ccc
column-rule-width列边框宽度1px
column-rule-style列边框样式solid, dashed, dotted
column-rule-color列边框颜色#ccc
column-span设置跨列none, all
column-fill设置列填充方式auto, balance
break-before设置元素前断点auto, avoid, column, page
break-after设置元素后断点auto, avoid, column, page
break-inside设置元素内断点auto, avoid, avoid-column, avoid-page

十六、用户界面属性

属性名用处示例值
cursor设置鼠标指针样式auto, pointer, text, move, not-allowed, url(cursor.cur)
user-select设置文本选择auto, none, text, all
pointer-events设置元素是否响应指针事件auto, none
resize设置元素可调整大小none, both, horizontal, vertical
caret-color设置插入光标颜色red, auto
accent-color设置强调色(表单控件)red, auto
appearance设置元素外观none, auto
scroll-behavior设置滚动行为auto, smooth
scroll-snap-type设置滚动捕捉类型none, x mandatory, y proximity
scroll-snap-align设置滚动捕捉对齐none, start, end, center
scroll-margin设置滚动外边距20px
scroll-padding设置滚动内边距20px
scrollbar-width设置滚动条宽度(Firefox)auto, thin, none
scrollbar-color设置滚动条颜色(Firefox)red blue

十七、内容生成

属性名用处示例值
content设置伪元素内容"文本", attr(data-text), counter(name)
quotes设置引号样式""" """ "'" "'"
counter-reset重置计数器section 0
counter-increment增加计数器section 1
counter-set设置计数器section 5

十八、打印属性

属性名用处示例值
page-break-before设置元素前分页auto, always, avoid, left, right
page-break-after设置元素后分页auto, always, avoid, left, right
page-break-inside设置元素内分页auto, avoid
orphans设置孤行数2
widows设置寡行数2

十九、CSS 变量(自定义属性)

属性名用处示例值
--custom-property定义 CSS 变量--primary-color: #3498db;
var()使用 CSS 变量color: var(--primary-color);

二十、其他属性

属性名用处示例值
all重置所有属性initial, inherit, unset, revert
contain设置元素包含none, layout, paint, size, strict, content
content-visibility设置内容可见性(性能优化)visible, auto, hidden
will-change提示浏览器元素将变化auto, transform, opacity
aspect-ratio设置宽高比16/9, 1, 4/3
object-fit设置替换元素适配方式fill, contain, cover, none, scale-down
object-position设置替换元素位置center, top left, 50% 50%
image-rendering设置图片渲染方式auto, crisp-edges, pixelated
touch-action设置触摸行为auto, none, pan-x, pan-y, manipulation
overscroll-behavior设置过度滚动行为auto, contain, none

二十一、逻辑属性(Logical Properties)

逻辑属性根据书写模式自动调整方向,支持国际化。

尺寸相关

属性名对应物理属性用处
inline-sizewidth设置内联尺寸
block-sizeheight设置块级尺寸
min-inline-sizemin-width最小内联尺寸
max-inline-sizemax-width最大内联尺寸
min-block-sizemin-height最小块级尺寸
max-block-sizemax-height最大块级尺寸

边距相关

属性名对应物理属性用处
margin-inlinemargin-left/right内联外边距
margin-blockmargin-top/bottom块级外边距
margin-inline-startmargin-left内联起始外边距
margin-inline-endmargin-right内联结束外边距
margin-block-startmargin-top块级起始外边距
margin-block-endmargin-bottom块级结束外边距
padding-inlinepadding-left/right内联内边距
padding-blockpadding-top/bottom块级内边距
padding-inline-startpadding-left内联起始内边距
padding-inline-endpadding-right内联结束内边距
padding-block-startpadding-top块级起始内边距
padding-block-endpadding-bottom块级结束内边距

边框相关

属性名对应物理属性用处
border-inlineborder-left/right内联边框
border-blockborder-top/bottom块级边框
border-inline-startborder-left内联起始边框
border-inline-endborder-right内联结束边框
border-block-startborder-top块级起始边框
border-block-endborder-bottom块级结束边框

定位相关

属性名对应物理属性用处
inset-inlineleft/right内联偏移
inset-blocktop/bottom块级偏移
inset-inline-startleft内联起始偏移
inset-inline-endright内联结束偏移
inset-block-starttop块级起始偏移
inset-block-endbottom块级结束偏移

二十二、CSS 函数

函数名用处示例
calc()计算值width: calc(100% - 50px);
min()取最小值width: min(500px, 100%);
max()取最大值width: max(300px, 50%);
clamp()限制范围font-size: clamp(1rem, 2vw, 3rem);
var()使用 CSS 变量color: var(--primary-color);
attr()获取属性值content: attr(data-text);
url()指定 URLbackground: url(image.jpg);
rgb()RGB 颜色color: rgb(255, 0, 0);
rgba()RGBA 颜色color: rgba(255, 0, 0, 0.5);
hsl()HSL 颜色color: hsl(0, 100%, 50%);
hsla()HSLA 颜色color: hsla(0, 100%, 50%, 0.5);
linear-gradient()线性渐变background: linear-gradient(red, blue);
radial-gradient()径向渐变background: radial-gradient(circle, red, blue);
conic-gradient()圆锥渐变background: conic-gradient(red, yellow, blue);
repeating-linear-gradient()重复线性渐变background: repeating-linear-gradient(red, blue 20px);
repeating-radial-gradient()重复径向渐变background: repeating-radial-gradient(red, blue 20px);
repeating-conic-gradient()重复圆锥渐变background: repeating-conic-gradient(red 0deg 10deg, blue 10deg 20deg);

二十三、选择器优先级

虽然不是属性,但了解选择器优先级对使用 CSS 至关重要。

选择器类型权重示例
!important最高color: red !important;
内联样式1000<div style="color: red;">
ID 选择器100#header
类选择器10.button
属性选择器10[type="text"]
伪类选择器10:hover, :first-child
标签选择器1div, p
伪元素选择器1::before, ::after
通配符选择器0*

二十四、常用单位

单位类型单位说明示例
绝对单位px像素16px
pt点(1pt = 1/72英寸)12pt
cm厘米2cm
mm毫米10mm
in英寸1in
pc派卡(1pc = 12pt)2pc
相对单位em相对父元素字体大小1.5em
rem相对根元素字体大小2rem
%百分比(相对父元素)50%
vw视口宽度的 1%50vw
vh视口高度的 1%100vh
vmin视口较小尺寸的 1%50vmin
vmax视口较大尺寸的 1%50vmax
ch字符 "0" 的宽度40ch
ex小写字母 "x" 的高度2ex
lh元素行高2lh
角度单位deg度(0-360)45deg
rad弧度1.57rad
grad百分度50grad
turn圈数0.5turn
时间单位s秒2s
ms毫秒500ms
频率单位Hz赫兹440Hz
kHz千赫兹2.5kHz
分辨率单位dpi每英寸点数96dpi
dpcm每厘米点数38dpcm
dppx每像素点数2dppx

二十五、关键字值

这些关键字可用于多个属性:

关键字说明适用场景
auto自动计算宽高、外边距等
inherit继承父元素的值所有属性
initial使用初始值所有属性
unset可继承则继承,否则初始值所有属性
revert恢复浏览器默认样式所有属性
currentColor当前 color 值颜色相关属性
transparent透明颜色相关属性

使用建议

  1. 常用优先:先掌握最常用的属性(盒模型、文本、定位、Flexbox)
  2. 分类记忆:按功能分类记忆,而不是逐个死记
  3. 实践为主:通过实际项目练习,加深理解
  4. 查阅习惯:不确定时查阅 MDN 或本手册
  5. 浏览器兼容:使用新特性时检查 Can I Use

快速查找技巧

  • Ctrl+F 搜索关键字
  • 查看目录快速定位分类
  • 收藏本文档方便随时查阅

持续更新中... 如有遗漏或错误,欢迎补充!

最后更新: 2026/6/13 22:15
贡献者: 52nnnn, Claude